/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Validation;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author sunwei
 */
public class PlanOrderValidator implements Validator{

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        long planOrder = (Long) value;
        Integer lotSize =(Integer) component.getAttributes().get("lotSize");
        long finalLotSize = Long.valueOf(lotSize.toString());
        System.out.println(planOrder);
        if(planOrder<0){
            throw new ValidatorException(new FacesMessage("plan orders contain negative values"));
        }
        if(planOrder%finalLotSize!=0){
            throw new ValidatorException(new FacesMessage("some plan orders are not in lot size"));
        }
    }
    
}
 